/*
 *所有关于PurchaseReturn类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*PurchaseReturnService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using XenFin.Read.System.IRepositories;
using SqlSugar;
using System;
using VOL.Core.DBManager;

namespace XenFin.Read.System.Services
{
    public partial class PurchaseReturnService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IPurchaseReturnRepository _repository;//访问数据库
        private readonly ISqlSugarClient _db;


        [ActivatorUtilitiesConstructor]
        public PurchaseReturnService(
            IPurchaseReturnRepository dbRepository,
            IHttpContextAccessor httpContextAccessor,
                        ISqlSugarClient db

            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            _db = db;

            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }

        WebResponseContent webResponse = new WebResponseContent();

        ///// <summary>
        ///// 新建
        ///// </summary>
        ///// <param name="saveDataModel"></param>
        ///// <returns></returns>
        //public override WebResponseContent Add(SaveModel saveDataModel)
        //{
        //    //此处saveModel是从前台提交的原生数据，可对数据进修改过滤
        //    AddOnExecute = (SaveModel saveModel) =>
        //    {
        //        //如果返回false,后面代码不会再执行
        //        return webResponse.OK();
        //    };
        //    // 在保存数据库前的操作，所有数据都验证通过了，这一步执行完就执行数据库保存
        //    AddOnExecuting = (PurchaseReturn purchaseReturn, object list) =>
        //    {
        //        var prefix = DateTime.Now.ToString("yyyyMMdd");
        //        var lastCategory = _db.Queryable<PurchaseReturn>()
        //                               .OrderByDescending(it => it.OrderReturnId)
        //                               .FirstOrDefault();

        //        int number = 0;
        //        if (lastCategory != null)
        //        {
        //            number = int.Parse(lastCategory.OrderReturnId.Substring(lastCategory.OrderReturnId.Length - 4)) + 1;
        //        }
        //        else
        //        {
        //            number = 1;
        //        }

        //        purchaseReturn.OrderReturnId = $"{"PR" + prefix}{number.ToString().PadLeft(4, '0')}";
        //        purchaseReturn.CreateTime = DateTime.Now;
        //        purchaseReturn.IsDeleted = 0;

        //        return webResponse.OK();
        //    };

        //    return base.Add(saveDataModel);
        //}
    }
}
